import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:hygf/page/home/customer_profile/view.dart';
import 'package:hygf/util/LoadingUtils.dart';

import '../../../../config/StyleConfig.dart';
import '../../../../res/HDColors.dart';
import '../../../../view/common_widget.dart';
import '../../../../view/empty_data_widget.dart';
import 'logic.dart';

class NetRecordPage extends StatelessWidget {
  NetRecordPage({Key? key}) : super(key: key);

  final logic = Get.put(NetRecordLogic());
  final state = Get.find<NetRecordLogic>().state;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: () async {
          logic.closePage();
          return false;
        },
        child: Scaffold(
          appBar: AppBar(
              title: const Text("并网记录"),
              elevation: 0,
              backgroundColor: HDColors.green,
              leading: CommonWidget.getAppBarLeading()),

          body: GetBuilder<NetRecordLogic>(builder: (logic) {
            return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CommonWidget.searchTitle(
                      state.searchController, (value) => {}, [], "",
                      searchHintText: "请输入手机号/客户姓名", onSubmitted: (value) {}),
                  CommonWidget.divider(0.5),
                  SizedBox(height: 10,),
                  Expanded(child: buildList())
                ]);
          }),
        ));
  }

  /// 数据列表
  buildList() {
    return GetBuilder<NetRecordLogic>(builder: (logic) {
      return EasyRefresh(
         enableControlFinishRefresh: true,
          enableControlFinishLoad: true,
          controller: state.controller,
          emptyWidget: state.dataList.isEmpty ? const EmptyDataWidget() : null,
          onRefresh: () async {
            state.noMore = true;
            state.controller.finishRefresh();
            logic.requestList(true);
          },
          onLoad: state.noMore
              ? null
              : () async {
                  logic.requestList(false);
                },
          child: ListView.separated(
            shrinkWrap: true,
            itemCount: state.dataList.length,
            itemBuilder: (BuildContext context, int index) {
              return CustomerProfilePage.buildProfileItem(index, state.dataList);
            },
            separatorBuilder: (BuildContext context, int index) {
              return Container(height: 10);
            },
          ));
    });
  }

}
